package com.lonely.web.controller.goods;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.goods.domain.dto.supplier.QuerySupplierPageDTO;
import com.lonely.goods.domain.dto.supplier.SupplierSubmitDTO;
import com.lonely.goods.domain.vo.supplier.SupplierPageQueryVO;
import com.lonely.goods.service.ISupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/7/7 13:22
 * @description: 供应商请求处理器
 */
@RestController
@RequestMapping("/goodsManager/supplier")
@Api(tags = "商品管理/供应商")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;


    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<SupplierPageQueryVO>> page(@RequestBody @Validated QuerySupplierPageDTO queryDto) {
        return R.data(this.supplierService.page(queryDto));
    }

    /**
     * 创建供应商
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "创建供应商")
    @SaCheckPermission("goods:supplier:create")
    public R<Boolean> create(@RequestBody @Validated SupplierSubmitDTO submitDto) {
        this.supplierService.create(submitDto);
        return R.status(true);
    }


    /**
     * 编辑供应商
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "编辑供应商")
    @SaCheckPermission("goods:supplier:edit")
    public R<Boolean> edit(@RequestBody @Validated SupplierSubmitDTO submitDto) {
        this.supplierService.edit(submitDto);
        return R.status(true);
    }

    /**
     * 启用供应商
     *
     * @param id
     * @return
     */
    @GetMapping("/enabled/{id}")
    @ApiOperation(value = "启用供应商")
    @SaCheckPermission("goods:supplier:enabled")
    public R<Boolean> enabled(@PathVariable("id") Long id) {
        this.supplierService.enabled(id);
        return R.status(true);
    }

    /**
     * 禁用供应商
     *
     * @param id
     * @return
     */
    @GetMapping("/disable/{id}")
    @ApiOperation(value = "禁用供应商")
    @SaCheckPermission("goods:supplier:disable")
    public R<Boolean> disable(@PathVariable("id") Long id) {
        this.supplierService.disable(id);
        return R.status(true);
    }


    /**
     * 获取供应商下拉列表
     *
     * @return
     */
    @GetMapping("/getSupplierSelect")
    @ApiOperation(value = "获取供应商下拉列表")
    public R<List<Select>> getSupplierSelect() {
        return R.data(this.supplierService.getSupplierSelect());
    }
}
